<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ElectPoolPrice extends BaseModel
{
    // use SoftDeletes;
    public $table = 'elect_pool_price';
    public $timestamps = true;
    static $unguarded = true;
    public $hidden = ["create_time", "update_time"];

    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';

    /*
    1 min < num < max
    2 num < min
    3 num > max
     */
    public static function getElectPoolPrice($num = 0, $type=1)
    {
        $price = ElectPoolPrice::where("min", '<=' , $num)
            ->where("max", ">=", $num)
            ->orderby("max", "asc")
            ->first(["price", "superpick_price"]);

        if($type == 1) //互选
            return $price['price'];
        else if($type == 2) //超级心动
            return $price['superpick_price'] ?? 62;

        return $price;
    }
}